/* Copyright (c) 2010 Fabian Kulman
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <cmath>
#include <iostream>
#include <fstream>

#include "input.h"

#define FLUSH -1000

using namespace std;


double inputToRadianMapping( double f ){
	double pi = (double)M_PI;
	f = (f*pi)-(pi/3.0f);
	return f;
}

vector<double>* readValuesFromFile( int argc, const char **argv ){
	vector<double>* input = new vector<double>();	
	double buff;

	if( argc == 2){
		ifstream infile(argv[1]);

		if (infile.is_open()){
			
			while( !infile.eof() ){

				infile >> buff;

				if( buff >= 0.0 && buff <= 1.0 ){
					buff = inputToRadianMapping(buff);
					input->push_back(buff);
				}
				else if( buff != FLUSH ){
					cout << buff << " is not a valid parameter. Input values have to lay between 0.0 and 1.0." << endl;
				}	
				buff = FLUSH;	// For the case of empty lines at the end of the input file
			}
			infile.close();
		}
		else{
			cout << "Input file could not be opened." << endl;
		}
	}
	else{
		cout << "The number command line arguments is not equal 2." << endl;
		cout << "Has the program been started from a .fr datafile?" << endl;
	}
	return input;
}